import { BaseWindow } from "../../../component/window/BaseWindow";
import { IClean } from "../../../../com/gengine/core/IClean";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { GameController } from "../../mvc/GameController";
import { ObjCreate } from "../common/ObjCreate";
import { GButton } from "../../../../com/mui/controls/GButton";
import { EffectManager } from "../../manager/EffectManager";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { LineBox } from "../guide/LineBox";
import { ItemData } from "../../resource/info/ItemData";
//class PetEquipGuideWindow
    
    export  class PetEquipGuideWindow extends BaseWindow implements IClean
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(460, 300);
            titleHeight = 26;
            title = Language.getString(61351);
            layer = GameController.petEquip.view as ILayer;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bg = ObjCreate.createBitmap("", 15, 35, this);
            this._upgradeSprite = new Object /* flash.display.Sprite */();
            var loc1=new GButton();
            loc1.label = Language.getString(61352);
            loc1.x = 140;
            loc1.y = 260;
            loc1.width = 96;
            loc1.height = 28;
            loc1.styleName = "Button";
            this._upgradeSprite.addChild(loc1);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onGotoRecastHandler);
            this._lineBox = EffectManager.getLineBox(96, 28);
            this._lineBox.x = 140;
            this._lineBox.y = 260;
            this._upgradeSprite.addChild(this._lineBox);
            var loc2=new GButton();
            loc2.label = Language.getString(61353);
            loc2.x = 250;
            loc2.y = 260;
            loc2.width = 70;
            loc2.height = 28;
            loc2.styleName = "Button";
            this._upgradeSprite.addChild(loc2);
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.cancelHandler);
            this._recastSprite = new Object /* flash.display.Sprite */();
            ObjCreate.createBitmap(ImagesConst.Fire, 110, 260, this._recastSprite);
            var loc3=ObjCreate.createTextField("", 132, 268, 280, 20, this._recastSprite);
            loc3.htmlText = Language.getString(61355) + HTMLUtil.addColor("<u><a href=\'event: 0\'>" + Language.getString(61354) + "</a></u>", "#00ff00");
            loc3.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._lineBox) 
            {
                EffectManager.disposeLineBox(this._lineBox);
            }
            return;
        }

        /* internal  */onGotoRecastHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            instance.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipUpgradeGuide, this.itemData));
            this.clean();
            return;
        }

        /* internal  */cancelHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            instance.hide();
            this.clean();
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            instance.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmeltOpenSmeltByPlanCode, {"code": 4110007, "isGuide": true}));
            this.clean();
            return;
        }

        public clean(): void
        {
            instance == null;
            return;
        }

        public updateDisplayListByType(arg1: string=""): void
        {
            if (arg1 != PetEquipGuideWindow.PET_EQUIP_UPGRADE_GUIDE) 
            {
                if (arg1 != PetEquipGuideWindow.PET_EQUIP_RECAST_GUIDE) 
                {
                    DisplayUtil.removeMe(this._recastSprite);
                    DisplayUtil.removeMe(this._upgradeSprite);
                }
                else 
                {
                    if (!instance.contains(this._recastSprite)) 
                    {
                        instance.addChild(this._recastSprite);
                    }
                    DisplayUtil.removeMe(this._upgradeSprite);
                }
            }
            else 
            {
                if (!instance.contains(this._upgradeSprite)) 
                {
                    instance.addChild(this._upgradeSprite);
                }
                DisplayUtil.removeMe(this._recastSprite);
            }
            return;
        }

        public loadBG(arg1: string): void
        {
            if (arg1 != ImagesConst.GuidePetInlayJewel) 
            {
                layer = GameController.petEquip.view as ILayer;
            }
            else 
            {
                layer = GameController.jewel.view as ILayer;
            }
            LoaderHelp.setBitmapdata(arg1 + ".swf", this._bg);
            instance.show(330, 85);
            return;
        }

        public static get instance(): PetEquipGuideWindow
        {
            if (PetEquipGuideWindow._instance == null) 
            {
                PetEquipGuideWindow._instance = new PetEquipGuideWindow();
            }
            return PetEquipGuideWindow._instance;
        }

        public static /* const */PET_EQUIP_UPGRADE_GUIDE: string="pet_equip_upgrade_guide";

        public static /* const */PET_EQUIP_RECAST_GUIDE: string="pet_equip_recast_guide";

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_upgradeSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_recastSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_lineBox: LineBox;

        public /* var */itemData: ItemData;

        /* internal */ static /* var */_instance: PetEquipGuideWindow;
    }
